import {useCallback, MutableRefObject} from 'react'
export default function useConfigApi(configEvents: MutableRefObject<object>) {
    return useCallback(async <T extends (...params: any) => Promise<any>>({
        request,
        params,
        keys: [onParams, onRequest, onData]
      }:{
          request: T,
          params: Parameters<T>[0],
          keys: string[]
          //@ts-ignore
      }): ReturnType<T> => {
          const newParams = (await configEvents.current?.[onParams!]?.(params)) || params;
          const data = await (configEvents.current?.[onRequest] || request)(newParams)
          return await configEvents.current?.[onData]?.(data, newParams) || data
      }, [configEvents]);
}